﻿using System;
using UnityEngine;

public class AttackState : SoldierState
{
    public AttackState(SoldierStateManager stateManager) :base(stateManager)//构造函数，继承子类的两个变量
    {
        _stateID = StateID.eStateID_Object_Attack;               //初始化状态ID为站立的ID
    }

    public override void FixedUpdate()
    {
    }

    public override void OnEnter()                           //刚进入状态时主角执行动作
    {
        m_Animator.SetBool("TargetInRange", true);
        m_NavAgent.isStopped = true;
    }

    public override void ProcessTransition()
    {
        m_soldier.DoAttack();
        if (m_soldier.target != null && (m_Model.transform.position - m_soldier.target.transform.position).magnitude > m_soldier.attackRange)
        {
            m_NavAgent.isStopped = false;
            
            m_StateManager.SetTransition(Transition.eTransiton_Object_Run); //调用Idle函数（参数为跑）
        }
        if (m_soldier.target == null)
        {
            m_NavAgent.isStopped = true;
            m_StateManager.SetTransition(Transition.eTransiton_Object_Idle); //调用Idle函数（参数为待命）
        }
        if (m_soldier.currentHP <= 0)
        {
            m_StateManager.SetTransition(Transition.eTransiton_Object_Dead);
        }
    }

    public override void OnExit()
    {
        m_Animator.SetBool("TargetInRange", false);
    }

    public override void Update()
    {
    }
}